﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ElfTyping.States.GameState.Entities
{
    public abstract class HealthEntity : Entity
    {
        public int CurrentHealth { get; protected set; }

        private int _maximumHealth;
        public int MaximumHealth
        {
            get { return _maximumHealth; }
            protected set
            {
                _maximumHealth = value;
                CurrentHealth = value;
            }
        }

        private HealthBar _healthBar = null;
        protected HealthBar HealthBar
        {
            get
            {
                if (_healthBar == null)
                {
                    _healthBar = new HealthBar(this);
                }

                return _healthBar;
            }
        }

        public override void Draw(General.Camera camera)
        {
            HealthBar.Draw(camera);

            base.Draw(camera);
        }

        public void TakeDamage(int damage)
        {
            CurrentHealth -= damage;
            if (CurrentHealth <= 0)
            {
                Die();
            }
        }

        public virtual void GainHealth(int health)
        {
            CurrentHealth += health;
            CurrentHealth = (CurrentHealth > MaximumHealth) ? MaximumHealth : CurrentHealth;
        }

        protected virtual void Die()
        {
        }

        public HealthEntity(GameScript script, Vector2 centerPosition)
            : base(script, centerPosition) { }
    }
}
